<template>
	<view class="withdraw">
		<view class="box">
			<view>
				<view>
					<view class="title">
						<text style="font-size: 30upx;">到账银行</text>
						<view class="bank" >
							<picker class="picker-item" mode="selector" :range="bankList" @change="onPicker">
								<view style="font-size: 28upx;" :class="bankText == '选择银行卡'?'defaultCla' : 'defaultClass'">{{bankText}}</view>
							</picker>
							<!-- <text class="iconfont" style="margin-right: 30upx;">&#xe632;</text> -->
						</view>
					</view>
					<view class="amount">
						<text style="font-size: 30upx;">提现金额</text>
						<view class="input">
							<text>￥</text>
							<input type="number" maxlength="6" v-model="money"
							focus="true"
							:class="money == ''?'amount-item' : 'amount-item1'"
							
							placeholder-style="font-size: 24upx !important; color: #999;"/>
						</view>

					</view>
					<view class="btn">
						<button type="primary" @click="widthdraw">确认提现</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations} from "vuex"
	export default {
		data() {
			return {
				money: '',
				bankText: '选择银行卡', 
				bankList: [],
				bankIdList: [],
				bankId: '', // 选中的银行卡ID
				currentDate: ''
			}
		},
		onLoad() {
			this.getBankCard();
		},
		methods: {
			...mapMutations(['setWithDraw']),
			onPicker(e){
				this.bankText = this.bankList[e.detail.value];
				this.bankId = this.bankIdList[e.detail.value];
			},
			async getBankCard() { // 银行卡列表
				let a = await this.$http.getBankCard();
				a.data.forEach((item) => {
					this.bankIdList.push(item.bankid);
					this.bankList.push(`${item.bank_name}(${item.bankcard_show})`);
				})
			},
			async widthdraw(){ // 提现
				if(!this.bankId){
					uni.showToast({
						title: '请选择银行卡后再操作',
						icon: 'none'
					})
					return
				}
				if(this.money < 10){
					uni.showToast({
						title: '请至少提现10元',
						icon: 'none'
					})
					return
				}
				this.getTime();
				this.setWithDraw({amount: this.money, bankname: this.bankText, currentDate: this.currentDate});
				let aa = {
					amount: this.money,
					bankid: this.bankId
					
				}
				let a = await this.$http.applyWithdraw(aa);
				if(a.code == 200) {
					uni.showToast({
						title: a.message,
						icon:'none'
					})
					this.set
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/myStore/cashFinish'
						})
					},500)
					
					return
				}
				uni.showToast({
					title: a.message,
					icon:'none'
				})
			},
			getTime() {
				let date = new Date();
				let month = date.getMonth() + 1;
				let strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				let currentDate = month + "-" + strDate +
					" " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
					this.currentDate = currentDate
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import 'static/css/myStore.scss';
</style>
